package com.fy.distributor.controller;


import com.fy.common.api.CommonResult;
import com.fy.distributor.vo.EnterpriseInformationVo;
import com.fy.distributor.vo.EnterpriseVo;
import com.fy.distributor.vo.PersonalInformationVo;
import com.fy.distributor.vo.PersonalVo;
import com.fy.shop.api.DistributorService;
import com.fy.shop.dto.EnterpriseInformationDto;
import com.fy.shop.dto.PersonalInformationDto;
import com.fy.user.api.DistributorSpotService;
import com.fy.user.dto.EnterpriseDto;
import com.fy.user.dto.PersonalDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/show")
@Api(tags = "分销商入驻管理")
@RefreshScope
public class DistributorManagementController {

    @Autowired
    private DistributorService distributorService;

    @Autowired
    private DistributorSpotService distributorSpotService;

    @ApiOperation("个人分销商入驻")
    @PostMapping(value = "/addPersonal")
    public CommonResult addPersonal(@RequestBody PersonalVo personalVo)
    {
        PersonalDto personalDto = new PersonalDto();
        //将VO转成DTO
        BeanUtils.copyProperties(personalVo,personalDto);
        distributorSpotService.addPersonal(personalDto);
        return CommonResult.success(null);
    }

    @ApiOperation("编辑个人分销商信息")
    @PostMapping(value = "/seePersonal")
    public CommonResult editPersonal( PersonalInformationVo personalInformationVo)
    {
        PersonalInformationDto personalInformationDto = new PersonalInformationDto();
        //将VO转成DTO
        BeanUtils.copyProperties(personalInformationVo,personalInformationDto);
        distributorService.editPersonal(personalInformationDto);
        return CommonResult.success(null);
    }

    @ApiOperation("企业分销商入驻")
    @PostMapping(value = "/addEnterprise")
    public CommonResult addEnterprise(@RequestBody EnterpriseVo enterpriseVo)
    {
        EnterpriseDto enterpriseDto = new EnterpriseDto();
        BeanUtils.copyProperties(enterpriseVo,enterpriseDto);
        distributorSpotService.addEnterprise(enterpriseDto);
        return CommonResult.success(null);
    }

    @ApiOperation("编辑企业分销商信息")
    @PostMapping(value = "/updateEnterprise")
    public CommonResult editEnterprise(@RequestBody EnterpriseInformationVo enterpriseInformationVo)
    {
        EnterpriseInformationDto enterpriseInformationDto = new EnterpriseInformationDto();
        BeanUtils.copyProperties(enterpriseInformationVo,enterpriseInformationDto);
        distributorService.editEnterprise(enterpriseInformationDto);
        return CommonResult.success(null);
    }


}
